Skip to content

ZOD v4 JSON Schema#17

Open
waji-io wants to merge 1 commit intoSavory:mainfrom
waji-io:patch-1
Open

ZOD v4 JSON Schema#17
waji-io wants to merge 1 commit intoSavory:mainfrom
waji-io:patch-1

Conversation

@waji-io
Copy link
Copy Markdown

@waji-io waji-io commented Apr 12, 2026

Summary by CodeRabbit

  • Documentation
    • Revamped OpenAPI integration documentation with updated, practical examples for request body and query parameter validation
    • Introduced Zod Version 4 support section with comprehensive examples for schema conversion utilities
    • Simplified setup process by removing outdated prerequisite requirements, improving the getting started experience

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 12, 2026

@waji-io is attempting to deploy a commit to the sorikairox's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 12, 2026

📝 Walkthrough

Walkthrough

The documentation for Danet's Zod OpenAPI integration was updated to remove outdated prerequisites about extending Zod with external packages, replace SwaggerModule explanation with modern decorator-based validation examples, and add a new section documenting Zod v4 support with relevant utility methods.

Changes

Cohort / File(s) Summary
Documentation Update
src/zod/openapi.md
Updated introduction to reference Controllers documentation; removed Pre-requisites section about @anatine/zod-openapi; replaced SwaggerModule and @ReturnedSchema explanations with focused examples using @danet/zod decorators; added new "ZOD Version 4 Support" section documenting z.fromJSONSchema() and z.toJSONSchema() utilities.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A tale of docs rewritten with care,
Where Zod v4 now breathes fresh air,
Old schemas fade, new decorators shine,
Controllers and queries in perfect line,
The OpenAPI path, now crystal and clear! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'ZOD v4 JSON Schema' directly addresses the main addition to the changeset—the new ZOD Version 4 Support section documenting JSON Schema conversion methods.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/zod/openapi.md`:
- Around line 19-27: The examples use z.object and z.infer but never import z,
so add the missing import (e.g., "import { z } from 'zod';") at the top of each
TypeScript snippet that defines CreateTodoSchema (the snippets referencing
z.object and type CreateTodoSchema = z.infer<...>) so the examples are
copy-paste runnable; apply the same change to the second example as noted (lines
showing the same CreateTodoSchema usage).
- Line 7: The intro warning contains duplicated wording "familiar with are
familiar with"; update the sentence in src/zod/openapi.md (the intro warning
line) to read cleanly, e.g. "This page assumes that you are familiar with
Danet's controllers. If you are not, please read the
[Controllers](/overview/controllers) page first." — remove the extra "are
familiar with" and ensure spacing and punctuation are correct.
- Around line 70-80: The heading level jumps from "# ZOD Version 4 Support" to
"### z.fromJSONSchema()", causing an MD001 lint error; change the "###
z.fromJSONSchema()" heading to "## z.fromJSONSchema()" so it is a second-level
heading like "## z.toJSONSchema()", ensuring consistent heading hierarchy and
keeping "## z.toJSONSchema()" unchanged.
- Around line 72-108: The docs incorrectly claim `@danet/zod`@^0.1.0 (and thus Zod
v4) is supported and show examples for z.fromJSONSchema() / z.toJSONSchema();
update the section to reflect reality by removing or correcting the Zod v4 claim
and the non-working examples: state that current `@danet/zod` (latest 0.0.9)
targets Zod v3 (≈3.23.8), remove or replace the z.fromJSONSchema() example
(since fromJSONSchema is not available in Zod v3 and is experimental in Zod v4),
and either remove the z.toJSONSchema() example or rewrite it to demonstrate only
features supported by Zod v3; also remove the version string `@danet/zod`@^0.1.0
or change it to the actual released version and add a short note indicating that
Zod v4 support is not yet available.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0dde30c9-4c84-49cd-b426-1298ef9af7d1

📥 Commits

Reviewing files that changed from the base of the PR and between 3a688ab and 58a304a.

📒 Files selected for processing (1)
  • src/zod/openapi.md

Comment thread src/zod/openapi.md

::: danger
The SwaggerModule is currently in Alpha, maaaany features are missing. If something you need is not here yet, [please fill an issue/feature request](https://github.com/Savory/Danet-Swagger/issues)
This page assumes that you are familiar with are familiar with Danet's controllers. If you are not, please read the [Controllers](/overview/controllers) page first.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix duplicated wording in the intro warning.

There’s a typo: “familiar with are familiar with”.

Suggested fix
-This page assumes that you are familiar with are familiar with Danet's controllers. If you are not, please read the [Controllers](/overview/controllers) page first.
+This page assumes that you are familiar with Danet's controllers. If you are not, please read the [Controllers](/overview/controllers) page first.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
This page assumes that you are familiar with are familiar with Danet's controllers. If you are not, please read the [Controllers](/overview/controllers) page first.
This page assumes that you are familiar with Danet's controllers. If you are not, please read the [Controllers](/overview/controllers) page first.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/zod/openapi.md` at line 7, The intro warning contains duplicated wording
"familiar with are familiar with"; update the sentence in src/zod/openapi.md
(the intro warning line) to read cleanly, e.g. "This page assumes that you are
familiar with Danet's controllers. If you are not, please read the
[Controllers](/overview/controllers) page first." — remove the extra "are
familiar with" and ensure spacing and punctuation are correct.

Comment thread src/zod/openapi.md
Comment on lines +19 to +27
import { Controller, Post } from '@danet/core';
import { Body } from '@danet/zod';

Danet Swagger module uses the following versions:
const CreateTodoSchema = z.object({
title: z.string(),
description: z.string(),
});

```
"zod": "npm:zod@3.23.8",
"zod-openapi": "npm:@anatine/zod-openapi@2.2.6"
```
type CreateTodoSchema = z.infer<typeof CreateTodoSchema>;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Add missing z import in both TypeScript examples.

Both snippets use z.object / z.infer but don’t import z, so the examples aren’t copy-paste runnable.

Suggested fix
 import { Controller, Post } from '@danet/core';
 import { Body } from '@danet/zod';
+import { z } from 'zod';
 import { Controller, Get } from '@danet/core';
 import { Query } from '@danet/zod';
+import { z } from 'zod';

Also applies to: 45-53

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/zod/openapi.md` around lines 19 - 27, The examples use z.object and
z.infer but never import z, so add the missing import (e.g., "import { z } from
'zod';") at the top of each TypeScript snippet that defines CreateTodoSchema
(the snippets referencing z.object and type CreateTodoSchema = z.infer<...>) so
the examples are copy-paste runnable; apply the same change to the second
example as noted (lines showing the same CreateTodoSchema usage).

Comment thread src/zod/openapi.md
Comment on lines +70 to +80
# ZOD Version 4 Support

Danet now supports Zod version 4 `@danet/zod@^0.1.0`, which is a major upgrade from version 3.

::: note
All previous versions of `@danet/zod` support only Zod version 3.
:::

One of the new features is the ability to generate JSON Schema from Zod schemas and vice versa.

### z.fromJSONSchema()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix heading-level jump to satisfy markdown lint.

Line 80 jumps to ### right after a # heading, which violates MD001.

Suggested fix
-### z.fromJSONSchema()
+## z.fromJSONSchema()

(And keep ## z.toJSONSchema() at Line 97, which then matches correctly.)

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# ZOD Version 4 Support
Danet now supports Zod version 4 `@danet/zod@^0.1.0`, which is a major upgrade from version 3.
::: note
All previous versions of `@danet/zod` support only Zod version 3.
:::
One of the new features is the ability to generate JSON Schema from Zod schemas and vice versa.
### z.fromJSONSchema()
# ZOD Version 4 Support
Danet now supports Zod version 4 `@danet/zod@^0.1.0`, which is a major upgrade from version 3.
::: note
All previous versions of `@danet/zod` support only Zod version 3.
:::
One of the new features is the ability to generate JSON Schema from Zod schemas and vice versa.
## z.fromJSONSchema()
🧰 Tools
🪛 markdownlint-cli2 (0.22.0)

[warning] 80-80: Heading levels should only increment by one level at a time
Expected: h2; Actual: h3

(MD001, heading-increment)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/zod/openapi.md` around lines 70 - 80, The heading level jumps from "# ZOD
Version 4 Support" to "### z.fromJSONSchema()", causing an MD001 lint error;
change the "### z.fromJSONSchema()" heading to "## z.fromJSONSchema()" so it is
a second-level heading like "## z.toJSONSchema()", ensuring consistent heading
hierarchy and keeping "## z.toJSONSchema()" unchanged.

Comment thread src/zod/openapi.md
Comment on lines +72 to +108
Danet now supports Zod version 4 `@danet/zod@^0.1.0`, which is a major upgrade from version 3.

::: note
All previous versions of `@danet/zod` support only Zod version 3.
:::

One of the new features is the ability to generate JSON Schema from Zod schemas and vice versa.

### z.fromJSONSchema()

```ts
@ReturnedSchema(TodoSchema)
@Get(':id')
async getById(@Param('id') id: string): Todo {
return this.todoService.getById(id);
}
import { z } from 'zod';

const jsonSchema = {
type: 'object',
properties: {
name: { type: 'string' },
age: { type: 'number' }
},
required: ['name', 'age']
};

const zodSchema = z.fromJSONSchema(jsonSchema);
```

If your route returns an array, pass `true` as the second argument of `ReturnedSchema` :

### z.toJSONSchema()

```ts
@ReturnedSchema(TodoSchema, true)
@Get()
async getTodos(): Todo[] {
return this.todoService.getAll();
}
``` No newline at end of file
import { z } from 'zod';

const zodSchema = z.object({
name: z.string(),
age: z.number()
});

const jsonSchema = z.toJSONSchema(zodSchema);
```
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🌐 Web query:

For Zod v4, are z.fromJSONSchema()andz.toJSONSchema()official public APIs? Also verify whether@danet/zod@^0.1.0 is documented as the version that adds Zod v4 support.

💡 Result:

For Zod v4, z.toJSONSchema is an official public API, introduced as a stable first-party feature in the release notes and documented in the JSON Schema guide. z.fromJSONSchema is also an official API but marked as experimental and not part of the stable API, likely to change in future releases, as stated in the official JSON Schema documentation. @danet/zod@^0.1.0 is not documented as the version adding Zod v4 support. The latest version is 0.0.9 (published ~5 months ago), and Danet documentation specifies compatibility with Zod 3.23.8. No changelog, release notes, or documentation mention Zod v4 support in any version, including around 0.1.0.

Citations:


Remove or correct section claiming Zod v4 support—it does not exist in @danet/zod.

The documentation claims @danet/zod@^0.1.0 adds Zod v4 support, but the latest published version is 0.0.9 (released ~5 months ago) and only supports Zod 3.23.8. No version of @danet/zod supports Zod v4. Additionally, z.fromJSONSchema() is marked experimental in Zod v4 and not part of the stable API. The code examples shown cannot execute with the current package. Either remove this section or update it to reflect actual Zod 3 capabilities.

🧰 Tools
🪛 markdownlint-cli2 (0.22.0)

[warning] 80-80: Heading levels should only increment by one level at a time
Expected: h2; Actual: h3

(MD001, heading-increment)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/zod/openapi.md` around lines 72 - 108, The docs incorrectly claim
`@danet/zod`@^0.1.0 (and thus Zod v4) is supported and show examples for
z.fromJSONSchema() / z.toJSONSchema(); update the section to reflect reality by
removing or correcting the Zod v4 claim and the non-working examples: state that
current `@danet/zod` (latest 0.0.9) targets Zod v3 (≈3.23.8), remove or replace
the z.fromJSONSchema() example (since fromJSONSchema is not available in Zod v3
and is experimental in Zod v4), and either remove the z.toJSONSchema() example
or rewrite it to demonstrate only features supported by Zod v3; also remove the
version string `@danet/zod`@^0.1.0 or change it to the actual released version and
add a short note indicating that Zod v4 support is not yet available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant